﻿using MVC5Test.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC5Test.Controllers
{
    /// <summary>
    /// 页面数据向后台传输
    /// </summary>
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            var user = new CurrentUser() { Id = new Random().Next(1, 10), Name = "翟超", Age = 20 };
            return View(user);
        }

        /// <summary>
        /// 登录页面
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "数据有误！！");
                return View(model);
            }
            if (!model.Email.Equals("332437232@qq.com"))
            {
                ModelState.AddModelError("", "用户邮箱填写有误！");
                return View(model);
            }
            if (!"zc901205".Equals(model.Password))
            {
                ModelState.AddModelError("", "密码错误");
                return View(model);
            }

            return RedirectToAction("Index");
        }
    }
}